<?php

class HomeController extends FController {

    public function actions() {
        return array(
            'captcha' => array(
                'class'       => 'CCaptchaAction',
                'backColor'   => 0xEFF0F0,
                'transparent' => false,
                'foreColor'   => 0x0dae4b,
                'height' => 30,
                'width' => 100,
            ),
        );
    }

    public function actionIndex() {
        $this->layout = '//front/home';
        $this->render('index');
    }
    
    public function actionContact() {
        $this->layout = '//front/home';
        Yii::import('application.modules.dadmin.models.DComContact');
        
        $model = new DComContact;
        $model->getData();
        
        $form = new ContactForm('contact');
        if ( isset($_POST['ContactForm']) ) {
            $form->attributes = $_POST['ContactForm'];
            $form->isEntering = true;

            if ( $form->validate() ) {
                $mailObj = new SendMail('', '', $form->renderHtml());
                $mailObj->replyTo = $form->email;
                
                if ( $form->fileUploadedInst ) {
                    $mailObj->attachedFile = $form->fileUploadedInst;
                }

                if ( $mailObj->send() ) {
                    Yii::app()->user->setState('message', 'contact_sendmail_success');
                    $this->redirect('contact');
                }
            }
        }

        $this->render('contact', array(
            'model' => $model,
            'form'  => $form,
        ));
    }
    
    public function actionMap() {
        if (Yii::app()->request->isAjaxRequest) {
            $this->layout = '//front/main_none';
            $this->render('map');
        } else {
            throw new CHttpException('403', 'Forbidden');
        }
    }
    
    public function actionDetail($page = '') {
        $this->layout = '//front/home';
        $model = new FNews();
        $data  = $model->getDetail($page);

        if ($data) {
            $this->render('detail', array(
                'model' => $model,
                'data' => $data,
            ));
        } else {
            throw new CHttpException('403', 'Bad request');
        }
    }
}